package com.cloud.custom.tasklist.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.custom.common.consts.CustomConsts;
import com.cloud.custom.common.context.HumanSession;
import com.cloud.custom.common.utils.SessionHelper;
import com.cloud.custom.interfaces.FeignClientSystem;
import com.cloud.custom.tasklist.service.TaskListSqlContextService;

@Service
public class TaskListSqlContextServiceImpl implements TaskListSqlContextService {

	@Autowired
	private FeignClientSystem feignClientSystem;

	@Override
	public Map<String, String> initSqlContextMap() {
		Map<String, String> result = new HashMap<String, String>();
		HumanSession session = SessionHelper.get();
		result.put(CustomConsts.CONTEXT_HUMAN_ID, session.getHumanId() + "");
		result.put(CustomConsts.CONTEXT_HUMAN_NAME, session.getHumanName());
		result.put(CustomConsts.CONTEXT_UNIT_ID, session.getUnitId() + "");
		result.put(CustomConsts.CONTEXT_UNIT_NAME, session.getUnitName());
		List<Long> partIds = new ArrayList<Long>();
		partIds.add(0L);
		partIds.add(session.getHumanId());
		partIds.add(session.getUnitId());
		partIds.addAll(session.getRoleIds());
		result.put(CustomConsts.CONTEXT_PART_ID, StringUtils.join(partIds, ","));
		//调用接口获取数据
		Map<String, String> sysParams = feignClientSystem.getSystemParams(session.getHumanId());
		result.putAll(sysParams);
		return result;
	}

}
